package com.algorithm.treenode;

import com.dataconsruct.TreeNode;


/**
 * 二叉树层序遍历，即广度遍历
 */
public class DeepSearchTest {
    public static void main(String[] args) {
        TreeNode leafTreeNode4 = new TreeNode(4);
        TreeNode leafTreeNode5 = new TreeNode(5);
        TreeNode leafTreeNode6 = new TreeNode(6);
        TreeNode leafTreeNode7 = new TreeNode(7);
        TreeNode treeNode2 = new TreeNode(2, leafTreeNode4, leafTreeNode5);
        TreeNode treeNode3 = new TreeNode(3, leafTreeNode6, leafTreeNode7);
        TreeNode root = new TreeNode(1, treeNode2, treeNode3);

        new DeepSearchTest().beforeOrderIter(root);
        System.out.println("-----------------");
        new DeepSearchTest().middleOrderIter(root);
        System.out.println("-----------------");
        new DeepSearchTest().afterOrderIter(root);
    }

    public void beforeOrderIter(TreeNode treeNode) {
        if (treeNode == null) {
            return;
        }
        System.out.println("前序遍历：" + treeNode.val);
        beforeOrderIter(treeNode.left);
        beforeOrderIter(treeNode.right);
    }

    public void middleOrderIter(TreeNode treeNode) {
        if (treeNode == null) {
            return;
        }
        middleOrderIter(treeNode.left);
        System.out.println("中序遍历：" + treeNode.val);
        middleOrderIter(treeNode.right);
    }

    public void afterOrderIter(TreeNode treeNode) {
        if (treeNode == null) {
            return;
        }
        afterOrderIter(treeNode.left);
        afterOrderIter(treeNode.right);
        System.out.println("后序遍历：" + treeNode.val);
    }

}
